<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="head.jsp"%>

<div class="am-cf admin-main">
	<!-- content start -->
	<div class="admin-content">
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf">
					<strong class="am-text-primary am-text-lg">构建项目</strong> / <small>项目列表</small>
				</div>
			</div>
			<hr>


			<div class="am-g">
				<div class="am-u-sm-12 am-u-md-6">
					<div class="am-btn-toolbar">
						<div class="am-btn-group am-btn-group-xs"></div>
					</div>
				</div>

				<div class="am-u-sm-14 am-u-md-1">
					<div class="am-input-group am-input-group-sm">
						<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only" href="project.jsp"><span class="am-icon-plus"></span>新增</a>
					</div>
				</div>
			</div>


			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form">
						<table class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
									<th class="table-author am-hide-sm-only">操作</th>
									<th class="table-author am-hide-sm-only">直接生成</th>
									<th class="table-id">GroupId</th>
									<th class="table-id">ArtifactId</th>
									<th class="table-title">VersionId</th>
									<th class="table-type">驱动名称</th>
									<th class="table-title">基础路径</th>
									<th class="table-id">前缀</th>
									<th class="table-title">扫描包名</th>
									<th class="table-title">mapper包名</th>
									<th class="table-title">实体包名</th>
									<th class="table-title">控制层包名</th>
									<th class="table-title">项目名称</th>
								</tr>
							</thead>
							<tbody id="id_tb_body">
							</tbody>
						</table>
						<hr>
						<p>说明：请确保该系统所在机器能访问你的数据库</p>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var metadata = [ 'groupId', 'artifactId', 'versionId', 'driverClassName',
			'basePath', 'pix', 'scanPackage', 'mapperPackage', 'poPackage',
			'controllerPackage', 'menuName' ];

	$(function() {
		loadData();
	});

	function loadData() {
		$.get("mvc/project/list", function(data) {
			filltr(data);
		});
	}

	function filltr(data) {
		data = data || [];
		$("#id_tb_body").html("");
		for ( var idx in data) {
			var context = "";
			var prj = data[idx];

			context += "<td>"
					+ '<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only" href="project.jsp?id='
					+ prj['id']
					+ '"><span class="am-icon-pencil-square-o"></span>编辑</a> '
					+ '<a class="am-btn am-btn-default am-btn-xs am-hide-sm-only"  href="javascript:deleteprj('
					+ prj['id']
					+ ')"><span class="am-icon-trash-o"></span>删除</a>'
					+ "</td>";

			context += '<td><a class="am-btn am-btn-default am-btn-xs am-hide-sm-only" target="_blank"  href="mvc/project/create?id='
					+ prj['id']
					+ '" ><span class="am-icon-pencil-square-o"></span>生成</a>  </td>';
			for ( var midx in metadata) {
				var key = metadata[midx];
				context += "<td>" + prj[key] + "</td>";
			}

			context = "<tr>" + context + "</tr>";

			$("#id_tb_body").append(context);
		}
	}

	function deleteprj(id) {
		$.get("mvc/project/delete?id=" + id, function(msg) {
			alert(msg);
			loadData();
		});
	}

	function createprj(id) {
		$.AMUI.progress.start();
		$.get("mvc/project/create?id=" + id, function(msg) {
			$.AMUI.progress.done(true);
			alert(msg);
		});
	}
</script>

<%@include file="bottom.jsp"%>